package com.ffms.servlet;

import com.ffms.entity.FamilyMember;
import com.ffms.entity.Shouru;
import com.ffms.service.AdminService;
import com.ffms.service.impl.AdminServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

@WebServlet("/AllShouruServlet")
public class AllShouruServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.获取用户请求数据
        Object user = request.getSession().getAttribute("user");
        AdminService adminService = new AdminServiceImpl();
        List<Shouru> shouruList;
        if (user instanceof FamilyMember) {
            FamilyMember familyMember = (FamilyMember) user;
            shouruList = adminService.findshouruByMid(familyMember.getSid());
        } else {
            shouruList = adminService.findshouru();
        }

        //2.调用业务层调取成员信息

        //3.跳转到显示成员页面
        request.setAttribute("shouruList", shouruList);
        request.getRequestDispatcher("admin/allShouruList.jsp").forward(request, response);
    }
}
